package com.taxi.driver.module.guide;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.taxi.driver.R;
import com.taxi.driver.common.BaseFragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 功能描述：
 */
public class GuideItemFragment extends BaseFragment {

    @BindView(R.id.iv_bg)
    ImageView mIvBg;
    @BindView(R.id.tv_start)
    TextView mTvStart;

    public static GuideItemFragment newInstance(int imageRes, boolean showSkip) {
        GuideItemFragment fragment = new GuideItemFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("imageRes", imageRes);
        bundle.putBoolean("showSkip", showSkip);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_guide_item, container, false);
        ButterKnife.bind(this, mView);
        Bundle arguments = getArguments();
        int imageRes = arguments.getInt("imageRes", 0);
        Glide.with(getContext()).load(imageRes).into(mIvBg); //显示引导图
        boolean showSkip = arguments.getBoolean("showSkip", false);
        mTvStart.setVisibility(showSkip ? View.VISIBLE : View.GONE); //控制跳转键的显示
        return mView;
    }

    @OnClick(R.id.tv_start)
    public void onClick() {
        if (getContext() instanceof GuideActivity) {
            ((GuideActivity) getContext()).start();
        }
    }
}
